function modelInit() {
    //面包屑
    if (modelIndex.crumbs && modelIndex.crumbs.length) {
        TV.structure(modelIndex.crumbs)
    }
    // structure
    var index;
    var page = 1;
    var indexList = new TV.CookieOpt().getOpt()
    console.log(indexList)
    if (indexList && JSON.stringify(indexList) != "{}" && typeof indexList.index == 'number') {
        index = indexList && typeof indexList.index == 'number' ? indexList.index : undefined;
        page = indexList && indexList.page ? indexList.page : 1;
    } else {
        cmsIndex.handle('left');
        var mdIndex = 0;
        if (indexList && indexList.modelIndex != -1) {
            mdIndex = indexList.modelIndex;
        }
        left.toggleFocus(mdIndex);
    }

    console.log(page, index)
    getMessage(page, modelIndex.pageSize, 'next', index);
}


/*
 * 0.左侧区
 */
cmsIndex.modules[cmsIndex.moduleGuid(cmsIndex.addModule())] = {
    modName: 'left',
    modNum: cmsIndex.moduleGuid(),
    map: {
        right: 1
    }
}
var left = cmsIndex.modules[cmsIndex.moduleGuid()].module = (function () {
    var mod = {
        modName: "left",
        modNum: cmsIndex.moduleGuid()
    },
        index = modelIndex.index, //位置
        listName = modelIndex.modelName,  //模块名
        containerId = modelIndex.modelContainerId; //包含模块的标签id

    mod.clean = function () {
        var elem = $("#" + containerId).children("." + listName);;
        length = $('#' + containerId).children("." + listName).length;
        for (i = 0; i < length; i++) {
            console.log(elem[i].className)
            elem[i].className = listName;
        }
    }
    //操作
    mod.toggleFocus = function (number) {
        var me = mod;
        if (number != undefined) {
            index = number;
        }
        // TV.IndexOpt(containerId, listName, index);
        var elem = $("#" + containerId).children("." + listName);
        // console.log(index)
        for (var i = 0; i < elem.length; i++) {
            elem[i].className = listName;
        }
        if (elem.length && typeof index == 'number') {
            elem[index].className = elem[index].className + ' active';
        }
        return me;
    };
    //index 位置调整
    mod.moveOp = function (directive) {
        var me = mod;
        index = direOpt(index, directive);
        mod.toggleFocus();
        return me;
    };
    mod.action = function (directive) {
        var me = mod;
        switch (directive) {
            case 'back':
                if (modelIndex.isVideo && mp) {
                    mp.stop();
                }
                if (modelIndex.disModel) {
                    Utility.ioctlWrite("skyworthKey", "Key2VOD");
                }
                history.go(-1);
                break;
            case 'enter':
                if (isCache) {
                    var cookieTv = new TV.CookieOpt({
                        modelIndex: index
                    })
                    var indexList = cookieTv.setOpt();
                }

                modelEnter(index);
                break;
        }
        return me;
    }

    mod.grabEvent = function (key) {
        var me = mod;
        var keyJson = TV.GetKey(key);
        if (keyJson.keyState && keyJson.keyState != 'enter' && keyJson.keyState != 'back') {
            me.moveOp(keyJson.keyState);
        } else {
            me.action(keyJson.keyState)
        }
        return keyJson.isBlock;


    };

    return mod;
})();
/*
 * 1.右侧区
 */

cmsIndex.modules[cmsIndex.moduleGuid(cmsIndex.addModule())] = {
    modName: 'right',
    modNum: cmsIndex.moduleGuid(),
    map: {
        left: 0
    }
};

var right = cmsIndex.modules[cmsIndex.moduleGuid()].module = (function () {
    var mod = {
        modName: "pageList",
        modNum: cmsIndex.moduleGuid()
    },
        index = modelIndex.index, //位置
        isLike = modelIndex.isLike,//是否开启点赞功能
        status = '1',//是否在外框
        length = 0, //真实长度
        nowPage = 1, //当前页数
        totalPage = 1,  //总页数
        type = modelIndex.type,//类型
        listName = modelIndex.listName,  //模块名
        pageSize = modelIndex.pageSize,//模块数量
        rowHeight = modelIndex.rowHeight,//多行模块行数
        containerId = modelIndex.listContainerId; //包含模块的标签id

    mod.clean = function () {
        var elem = $("#" + containerId).children("." + listName);
        for (i = 0; i < length; i++) {
            elem[i].className = listName;
        }
    }
    //操作
    mod.toggleFocus = function (number) {
        var me = mod;

        if (number != undefined) {
            index = number;
        }
        var elem = $("#" + containerId).children("." + listName);
        var elemCur = $("#" + containerId).children(".cur")

        for (i = 0; i < length; i++) {
            elem[i].className = listName;
            if (elemCur.length) {
                elemCur[i].className = 'cur';
            }
        }
        if (elem.length) {
            if (status == '0') {
                elemCur[index].className = elemCur[index].className + ' curActive'
            }
            elem[index].className = elem[index].className + ' active';
        }
        return me;
    };
    //赋值
    mod.initialization = function () {
        var me = mod;
        nowPage = parseInt(document.getElementById('now_page').innerHTML);
        totalPage = 1;
        length = $('#' + containerId).children("." + listName).length;
        console.log(containerId, listName, length, 1111111111111)
        return me;
    };
    //index 位置调整
    mod.moveOp = function (directive) {
        console.log(directive, type, length)
        var me = mod;
        if (directive == "backwards") {
            me.clean();
            cmsIndex.handle('left');
            if (modelIndex.id == 'study') {
                left.toggleFocus(3);
            } else {
                left.toggleFocus(1);
            }

        } else {
            if (directive == "up" && modelIndex.id == 'study' && index == 0) {
                left.toggleFocus(4);
                me.clean();
                cmsIndex.handle('left');
                return
            }
            var json = new TV.ListOperation({
                type: type,
                key: directive,
                isLike: isLike,
                status: status,
                nowPage: nowPage,
                totalPage: totalPage,
                pageSize: pageSize,
                length: length,
                index: index,
                rowHeight: rowHeight
            })
            var message = json.operation();
            console.log(message)
            index = message.index;
            status = message.status;
            if (message.position != '') {
                getMessage(message.nowPage, pageSize, message.position);  //下一页
            }

            mod.toggleFocus();
        }

        return me;
    };
    mod.action = function (directive) {
        var me = mod;
        switch (directive) {
            case 'back':
                if (modelIndex.disModel) {
                    Utility.ioctlWrite("skyworthKey", "Key2VOD");
                }
                history.go(-1);
                break;
            case 'enter':
                if (isCache) {
                    var cookieTv = new TV.CookieOpt({
                        index: index,
                        page: nowPage
                    })
                    var indexList = cookieTv.setOpt();
                }

                direEnter(index);

                break;
        }
        return me;
    };
    mod.grabEvent = function (key) {
        var me = mod;
        var keyJson = TV.GetKey(key);
        if (keyJson.keyState && keyJson.keyState != 'enter' && keyJson.keyState != 'back') {
            me.moveOp(keyJson.keyState);
        } else {
            me.action(keyJson.keyState)
        }
        return keyJson.isBlock;


    };

    return mod;
})();
$(window).unload(function () {
    if (modelIndex.isVideo && mp) {
        mp.stop();
    }
});
cmsIndex.run();